package com.cskaoyan.market.aspect;

import com.cskaoyan.market.util.ValidationUtils;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;
import org.springframework.validation.BindingResult;
/**
 * @Author: 鲸落
 * @Date: 2024/05/20/15:03
 * @Version: 1.0
 * @Description:
 */
@Component
@Aspect
public class ValidationAspect {

    @Pointcut("@annotation(com.cskaoyan.market.annotation.ValidParam)")
    public void pt(){}

    //什么通知？？？？？？
    @Before("pt()")
    public void valid(JoinPoint joinPoint){
        Object[] args = joinPoint.getArgs();
        for (Object arg : args) {
            if(arg instanceof BindingResult){
                ValidationUtils.validate((BindingResult) arg);
            }
        }
    }
}
